//获取分享服务列表
var shares = {};
mui.plusReady(function() {
	plus.share.getServices(function(s) {
		if (s && s.length > 0) {
			for (var i = 0; i < s.length; i++) {
				var t = s[i];
				shares[t.id] = t;
			}
		}
	}, function() {
		console.log("获取分享服务列表失败");
	});
});
//发送
function shareMessage(share, ex, href, title, content, thumbs) {
	var msg = {
		extra: {
			scene: ex
		}
	};
	msg.href = href;
	msg.title = title;
	msg.content = content;
	msg.thumbs = [thumbs];
	share.send(msg, function() {
		mui.toast("分享到\"" + share.description + "\"成功！ ");
		console.log("分享到\"" + share.description + "\"成功！ ");
	}, function(e) {
		console.log("分享到\"" + share.description + "\"失败: " + e.code + " - " + e.message);
	});
}

function share_to(type, sharet, href, title, content, thumbs) {
	console.log(type);
	var share = shares[type];
	if (share) {
		if (share.authenticated) { //认证授权
			shareMessage(share, sharet, href, title, content, thumbs);
		} else {
			share.authorize(function() {
				shareMessage(share, sharet, href, title, content, thumbs);
			}, function(e) {
				$.alert('请下载相应软件');
				console.log("认证授权失败：" + e.code + " - " + e.message);
			});
		}
	} else {
		mui.toast("无法获取分享服务")
	}
}
//复制链接到粘贴板
function copy_url() {
	var str = window.location.href;
				var t = str.replace('file:///storage/emulated/0/Android/data/io.dcloud.HBuilder/.HBuilder/apps/HBuilder/www', 'http/www.5itmw.com');
	if (plus.os.name == 'Android') {
		var Context = plus.android.importClass("android.content.Context");
		var main = plus.android.runtimeMainActivity();
		var clip = main.getSystemService(Context.CLIPBOARD_SERVICE);
		plus.android.invoke(clip, "setText", t);
	} else {
		var UIPasteboard = plus.ios.importClass("UIPasteboard");
		var generalPasteboard = UIPasteboard.generalPasteboard();
		//设置获取文本内容
		generalPasteboard.setValueforPasteboardType(t, "public.utf8-plain-text");
	}
	mui.toast('已成功复制到粘贴板');
}